package com.example.shipload_e.service;

import java.io.File;
import java.io.FileOutputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONObject;

import com.example.shipload_e.ShipMentWelcomeActivity;
import com.example.shipload_e.activitys.discharge_feedback.DisDailyShipmentCountListActivity;
import com.example.shipload_e.activitys.discharge_feedback.DischargeFinishListActivity;
import com.example.shipload_e.activitys.discharge_feedback.DischargeShipArrivalActivity;
import com.example.shipload_e.activitys.exception_feedback.ExceptionFeedbackListActivity;
import com.example.shipload_e.activitys.shipment_feedback.DailyShipmentCountListActivity;
import com.example.shipload_e.activitys.shipment_feedback.LeavePortListActivity;
import com.example.shipload_e.activitys.shipment_feedback.ShipArrivalActivity;
import com.example.shipload_e.activitys.shipment_feedback.ShipmentFinishListActivity;
import com.example.shipload_e.activitys.tasks_collect.TasksCollectListActivity;
import com.example.shipload_e.activitys.transport_feedback.TransportFeedbackListActivity;
import com.example.shipload_e.database_dao.DBUtil;
import com.example.shipload_e.util.HttpActConstant;
import com.example.shipload_e.util.HttpConstant;
import com.example.shipload_e.util.HttpUtil;
import com.example.shipload_e.util.PictureUtil;
import com.example.shipload_e.util.SharePreferenceUtil;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

/**
 * 发送请求线程
 * @author AIXL
 */
public class BizNetworkService implements Runnable {
	Handler	            handler;
	int	                opt_tag;
	Map<String, String>	params;
	Context	            ctx;

	public BizNetworkService(Context ctx, Handler handler, int tag, Map<String, String> params) {
		this.ctx = ctx;
		this.handler = handler;
		this.opt_tag = tag;
		this.params = (params == null ? new HashMap<String, String>() : params);
	}

	@Override
	public void run() {
		Message msg = new Message();
		Bundle data = new Bundle();
		msg.what = opt_tag;
		StringBuffer result = new StringBuffer();
		SharePreferenceUtil sp = new SharePreferenceUtil(ctx, HttpConstant.SAVE_USER);

		switch (opt_tag) {
		// 登录
			case HttpActConstant.LOGIN:
				try {
					System.out.println(params);
					result = HttpUtil.queryStringForPost(HttpActConstant.LOGIN_URL, params, ctx);
					System.out.println(result);
					JSONObject jresult = new JSONObject(result.toString());
					if(jresult.has("result") && jresult.getBoolean("result")) {
						data.putString(HttpConstant.SUBMIT_SUCCESS, HttpConstant.SUBMIT_SUCCESS);
						data.putString(HttpConstant.ACCOUNT, params.get(HttpConstant.ACCOUNT));
						data.putString(HttpConstant.PASSWORD, params.get(HttpConstant.PASSWORD));
					} else {
						data.putString(HttpConstant.SUBMIT_FAIL, HttpConstant.SUBMIT_FAIL);
					}
					String massege = jresult.has("msg") == false ? "" : jresult.getString("msg");
					data.putString("msg", massege);
				} catch (Exception e) {
					e.printStackTrace();
				}
				msg.setData(data);

				break;
			// 提交到港时间
			case HttpActConstant.SHIPMENT_ARRIVAL:
				try {
					System.out.println(params);
					result = HttpUtil
					        .queryStringForPost(HttpActConstant.SHIPMENT_ARRIVAL_URL, params, ctx);
					System.out.println(result);
					JSONObject jresult = new JSONObject(result.toString());
					if(jresult.getBoolean("result")) {
						data.putString(HttpConstant.SUBMIT_SUCCESS, HttpConstant.SUBMIT_SUCCESS);
						data.putString("msg", (jresult.has("msg") ? jresult.getString("msg")
						        : "提交成功！"));
					} else {
						data.putString(HttpConstant.SUBMIT_FAIL, HttpConstant.SUBMIT_FAIL);
						data.putString("msg", (jresult.has("msg") ? jresult.getString("msg")
						        : "提交失败，请重试..."));
					}
				} catch (Exception e) {
					data.putString("msg", "提交异常，请重试...");
					e.printStackTrace();
				}
				msg.setData(data);

				break;
			// 获取到港反馈任务
			case HttpActConstant.LOADING_ARRIVALTASKS:
				try {
					System.out.println(params);
					result = HttpUtil
					        .queryStringForPost(HttpActConstant.LOADING_ARRIVALTASKS_URL, params, ctx);
					System.out.println(result);
					JSONArray getResult = new JSONArray(result.toString());
					Intent in = null;
					if(result.length() > 0 && getResult.length() > 0) {
						in = new Intent(ctx, ShipArrivalActivity.class);
						in.putExtra("initResultMsg", "获取成功");
						in.putExtra("initResult", result.toString());
						ctx.startActivity(in);
					} else {
						in = new Intent(ctx, ShipMentWelcomeActivity.class);
						in.putExtra("initResultMsg", "暂无数据");
						ctx.startActivity(in);
					}

				} catch (Exception e) {
					data.putString("msg", "系统异常，请重试...");
					e.printStackTrace();
				}
				msg.setData(data);

				break;
			// 每日装船数
			case HttpActConstant.INIT_DAILY_SHIPMENT_COUNT_TASKS:
				try {
					System.out.println(params);
					result = HttpUtil
					        .queryStringForPost(HttpActConstant.INIT_DAILY_SHIPMENT_COUNT_TASKS_URL, params, ctx);
					System.out.println(result);
					JSONArray getResult = new JSONArray(result.toString());
					Intent in = null;
					if(result.length() > 0 && getResult.length() > 0) {
						in = new Intent(ctx, DailyShipmentCountListActivity.class);
						in.putExtra("initResultMsg", "获取成功");
						in.putExtra("initResult", result.toString());
						ctx.startActivity(in);
					} else {
						in = new Intent(ctx, ShipMentWelcomeActivity.class);
						in.putExtra("initResultMsg", "暂无数据");
						ctx.startActivity(in);
					}

				} catch (Exception e) {
					data.putString("msg", "系统异常，请重试...");
					e.printStackTrace();
				}
				msg.setData(data);

				break;
			// 提交每日装船数信息
			case HttpActConstant.SUBMIT_DAILY_SHIPMENT_COUNT_TASKS:
				try {
					System.out.println(params);
					result = HttpUtil
					        .queryStringForPost(HttpActConstant.SUBMIT_DAILY_SHIPMENT_COUNT_TASKS_URL, params, ctx);
					System.out.println(result);
					JSONObject jresult = new JSONObject(result.toString());
					if(jresult.getBoolean("result")) {
						data.putString(HttpConstant.SUBMIT_SUCCESS, HttpConstant.SUBMIT_SUCCESS);
						data.putString("msg", (jresult.has("msg") ? jresult.getString("msg")
						        : "提交成功！"));
					} else {
						data.putString(HttpConstant.SUBMIT_FAIL, HttpConstant.SUBMIT_FAIL);
						data.putString("msg", (jresult.has("msg") ? jresult.getString("msg")
						        : "提交失败，请重试..."));
					}
				} catch (Exception e) {
					data.putString("msg", "提交异常，请重试...");
					e.printStackTrace();
				}
				msg.setData(data);

				break;
			// 获取装船完成任务
			case HttpActConstant.INIT_SHIPMENT_FINISH_TASKS:
				try {
					System.out.println(params);
					result = HttpUtil
					        .queryStringForPost(HttpActConstant.INIT_SHIPMENT_FINISH_TASKS_URL, params, ctx);
					System.out.println(result);
					JSONArray getResult = new JSONArray(result.toString());
					Intent in = null;
					if(result.length() > 0 && getResult.length() > 0) {
						in = new Intent(ctx, ShipmentFinishListActivity.class);
						in.putExtra("initResultMsg", "获取成功");
						in.putExtra("initResult", result.toString());
						ctx.startActivity(in);
					} else {
						in = new Intent(ctx, ShipMentWelcomeActivity.class);
						in.putExtra("initResultMsg", "暂无数据");
						ctx.startActivity(in);
					}

				} catch (Exception e) {
					data.putString("msg", "系统异常，请重试...");
					e.printStackTrace();
				}
				msg.setData(data);

				break;
			// 提交装船完成信息
			case HttpActConstant.SUBMIT_SHIPMENT_FINISH_TASKS:
				try {
					System.out.println(params);
					result = HttpUtil
					        .queryStringForPost(HttpActConstant.SUBMIT_SHIPMENT_FINISH_TASKS_URL, params, ctx);
					System.out.println(result);
					JSONObject jresult = new JSONObject(result.toString());
					if(jresult.getBoolean("result")) {
						data.putString(HttpConstant.SUBMIT_SUCCESS, HttpConstant.SUBMIT_SUCCESS);
						data.putString("msg", (jresult.has("msg") ? jresult.getString("msg")
						        : "提交成功！"));
					} else {
						data.putString(HttpConstant.SUBMIT_FAIL, HttpConstant.SUBMIT_FAIL);
						data.putString("msg", (jresult.has("msg") ? jresult.getString("msg")
						        : "提交失败，请重试..."));
					}
				} catch (Exception e) {
					data.putString("msg", "提交异常，请重试...");
					e.printStackTrace();
				}
				msg.setData(data);
				break;
			// 获取离港反馈任务
			case HttpActConstant.INIT_SHIP_LEAVE_TASKS:
				try {
					System.out.println(params);
					result = HttpUtil
					        .queryStringForPost(HttpActConstant.INIT_SHIP_LEAVE_TASKS_URL, params, ctx);
					System.out.println(result);
					JSONArray getResult = new JSONArray(result.toString());
					Intent in = null;
					if(result.length() > 0 && getResult.length() > 0) {
						in = new Intent(ctx, LeavePortListActivity.class);
						in.putExtra("initResultMsg", "获取成功");
						in.putExtra("initResult", result.toString());
						ctx.startActivity(in);
					} else {
						in = new Intent(ctx, ShipMentWelcomeActivity.class);
						in.putExtra("initResultMsg", "暂无数据");
						ctx.startActivity(in);
					}

				} catch (Exception e) {
					data.putString("msg", "系统异常，请重试...");
					e.printStackTrace();
				}
				msg.setData(data);

				break;
			// 提交离港信息
			case HttpActConstant.SUBMIT_SHIP_LEAVE_TASKS:
				try {
					System.out.println(params);
					result = HttpUtil
					        .queryStringForPost(HttpActConstant.SUBMIT_SHIP_LEAVE_TASKS_URL, params, ctx);
					System.out.println(result);
					JSONObject jresult = new JSONObject(result.toString());
					if(jresult.getBoolean("result")) {
						data.putString(HttpConstant.SUBMIT_SUCCESS, HttpConstant.SUBMIT_SUCCESS);
						data.putString("msg", (jresult.has("msg") ? jresult.getString("msg")
						        : "提交成功！"));
					} else {
						data.putString(HttpConstant.SUBMIT_FAIL, HttpConstant.SUBMIT_FAIL);
						data.putString("msg", (jresult.has("msg") ? jresult.getString("msg")
						        : "提交失败，请重试..."));
					}
				} catch (Exception e) {
					data.putString("msg", "提交异常，请重试...");
					e.printStackTrace();
				}
				msg.setData(data);
				break;
			// 获取运输反馈任务
			case HttpActConstant.INIT_TRANSPORT_FEEDBACK_TASKS:
				try {
					System.out.println(params);
					result = HttpUtil
					        .queryStringForPost(HttpActConstant.INIT_TRANSPORT_FEEDBACK_TASKS_URL, params, ctx);
					System.out.println(result);
					JSONArray getResult = new JSONArray(result.toString());
					Intent in = null;
					if(result.length() > 0 && getResult.length() > 0) {
						in = new Intent(ctx, TransportFeedbackListActivity.class);
						in.putExtra("initResultMsg", "获取成功");
						in.putExtra("initResult", result.toString());
						ctx.startActivity(in);
					} else {
						in = new Intent(ctx, ShipMentWelcomeActivity.class);
						in.putExtra("initResultMsg", "暂无数据");
						ctx.startActivity(in);
					}

				} catch (Exception e) {
					data.putString("msg", "系统异常，请重试...");
					e.printStackTrace();
				}
				msg.setData(data);
				break;
			// 提交离港信息
			case HttpActConstant.SUBMIT_TRANSPORT_FEEDBACK_TASKS:
				try {
					System.out.println(params);
					result = HttpUtil
					        .queryStringForPost(HttpActConstant.SUBMIT_TRANSPORT_FEEDBACK_TASKS_URL, params, ctx);
					System.out.println(result);
					JSONObject jresult = new JSONObject(result.toString());
					if(jresult.getBoolean("result")) {
						data.putString(HttpConstant.SUBMIT_SUCCESS, HttpConstant.SUBMIT_SUCCESS);
						data.putString("msg", (jresult.has("msg") ? jresult.getString("msg")
						        : "提交成功！"));
					} else {
						data.putString(HttpConstant.SUBMIT_FAIL, HttpConstant.SUBMIT_FAIL);
						data.putString("msg", (jresult.has("msg") ? jresult.getString("msg")
						        : "提交失败，请重试..."));
					}
				} catch (Exception e) {
					data.putString("msg", "提交异常，请重试...");
					e.printStackTrace();
				}
				msg.setData(data);
				break;
			// 获取到港反馈任务,卸船
			case HttpActConstant.INIT_DISCHARGE_SHIP_ARRIVAL_TASKS:
				try {
					System.out.println(params);
					result = HttpUtil
					        .queryStringForPost(HttpActConstant.INIT_DISCHARGE_SHIP_ARRIVAL_TASKS_URL, params, ctx);
					System.out.println(result);
					JSONArray getResult = new JSONArray(result.toString());
					Intent in = null;
					if(result.length() > 0 && getResult.length() > 0) {
						in = new Intent(ctx, DischargeShipArrivalActivity.class);
						in.putExtra("initResultMsg", "获取成功");
						in.putExtra("initResult", result.toString());
						ctx.startActivity(in);
					} else {
						in = new Intent(ctx, ShipMentWelcomeActivity.class);
						in.putExtra("initResultMsg", "暂无数据");
						ctx.startActivity(in);
					}

				} catch (Exception e) {
					data.putString("msg", "系统异常，请重试...");
					e.printStackTrace();
				}
				msg.setData(data);

				break;
			// 提交到港时间，卸船
			case HttpActConstant.SUBMIT_DISCHARGE_SHIP_ARRIVAL_TASKS:
				try {
					System.out.println(params);
					result = HttpUtil
					        .queryStringForPost(HttpActConstant.SUBMIT_DISCHARGE_SHIP_ARRIVAL_TASKS_URL, params, ctx);
					System.out.println(result);
					JSONObject jresult = new JSONObject(result.toString());
					if(jresult.getBoolean("result")) {
						data.putString(HttpConstant.SUBMIT_SUCCESS, HttpConstant.SUBMIT_SUCCESS);
						data.putString("msg", (jresult.has("msg") ? jresult.getString("msg")
						        : "提交成功！"));
					} else {
						data.putString(HttpConstant.SUBMIT_FAIL, HttpConstant.SUBMIT_FAIL);
						data.putString("msg", (jresult.has("msg") ? jresult.getString("msg")
						        : "提交失败，请重试..."));
					}
				} catch (Exception e) {
					data.putString("msg", "提交异常，请重试...");
					e.printStackTrace();
				}
				msg.setData(data);

				break;
			// 每日卸船数
			case HttpActConstant.INIT_DAILY_DISCHARGE_COUNT_TASKS:
				try {
					System.out.println(params);
					result = HttpUtil
					        .queryStringForPost(HttpActConstant.INIT_DAILY_DISCHARGE_COUNT_TASKS_URL, params, ctx);
					System.out.println(result);
					JSONArray getResult = new JSONArray(result.toString());
					Intent in = null;
					if(result.length() > 0 && getResult.length() > 0) {
						in = new Intent(ctx, DisDailyShipmentCountListActivity.class);
						in.putExtra("initResultMsg", "获取成功");
						in.putExtra("initResult", result.toString());
						ctx.startActivity(in);
					} else {
						in = new Intent(ctx, ShipMentWelcomeActivity.class);
						in.putExtra("initResultMsg", "暂无数据");
						ctx.startActivity(in);
					}

				} catch (Exception e) {
					data.putString("msg", "系统异常，请重试...");
					e.printStackTrace();
				}
				msg.setData(data);

				break;
			// 提交每日卸船数
			case HttpActConstant.SUBMIT_DAILY_DISCHARGE_TASKS:
				try {
					result = HttpUtil
					        .queryStringForPost(HttpActConstant.SUBMIT_DAILY_DISCHARGE_TASKS_URL, params, ctx);
					System.out.println(result);
					JSONObject jresult = new JSONObject(result.toString());
					if(jresult.getBoolean("result")) {
						data.putString(HttpConstant.SUBMIT_SUCCESS, HttpConstant.SUBMIT_SUCCESS);
						data.putString("msg", (jresult.has("msg") ? jresult.getString("msg")
						        : "提交成功！"));
					} else {
						data.putString(HttpConstant.SUBMIT_FAIL, HttpConstant.SUBMIT_FAIL);
						data.putString("msg", (jresult.has("msg") ? jresult.getString("msg")
						        : "提交失败，请重试..."));
					}
				} catch (Exception e) {
					data.putString("msg", "提交异常，请重试...");
					e.printStackTrace();
				}
				msg.setData(data);

				break;
			// 获取卸船完成
			case HttpActConstant.INIT_DISCHARGE_FINISH_TASKS:
				try {
					System.out.println(params);
					result = HttpUtil
					        .queryStringForPost(HttpActConstant.INIT_DISCHARGE_FINISH_TASKS_URL, params, ctx);
					System.out.println(result);
					JSONArray getResult = new JSONArray(result.toString());
					Intent in = null;
					if(result.length() > 0 && getResult.length() > 0) {
						in = new Intent(ctx, DischargeFinishListActivity.class);
						in.putExtra("initResultMsg", "获取成功");
						in.putExtra("initResult", result.toString());
						ctx.startActivity(in);
					} else {
						in = new Intent(ctx, ShipMentWelcomeActivity.class);
						in.putExtra("initResultMsg", "暂无数据");
						ctx.startActivity(in);
					}

				} catch (Exception e) {
					data.putString("msg", "系统异常，请重试...");
					e.printStackTrace();
				}
				msg.setData(data);
				break;
			// 提交卸船完成
			case HttpActConstant.SUBMIT_ISCHARGE_FINISH_TASKS:
				try {
					System.out.println(params);
					result = HttpUtil
					        .queryStringForPost(HttpActConstant.SUBMIT_ISCHARGE_FINISH_TASKS_URL, params, ctx);
					System.out.println(result);
					JSONObject jresult = new JSONObject(result.toString());
					if(jresult.getBoolean("result")) {
						data.putString(HttpConstant.SUBMIT_SUCCESS, HttpConstant.SUBMIT_SUCCESS);
						data.putString("msg", (jresult.has("msg") ? jresult.getString("msg")
						        : "提交成功！"));
					} else {
						data.putString(HttpConstant.SUBMIT_FAIL, HttpConstant.SUBMIT_FAIL);
						data.putString("msg", (jresult.has("msg") ? jresult.getString("msg")
						        : "提交失败，请重试..."));
					}
				} catch (Exception e) {
					data.putString("msg", "提交异常，请重试...");
					e.printStackTrace();
				}
				msg.setData(data);
				break;
			// 获取异常反馈
			case HttpActConstant.INIT_EXCEPTION_FEEDBACK_TASKS:
				try {
					System.out.println(params);
					result = HttpUtil
					        .queryStringForPost(HttpActConstant.INIT_EXCEPTION_FEEDBACK_TASKS_URL, params, ctx);
					System.out.println(result);
					JSONArray getResult = new JSONArray(result.toString());
					Intent in = null;
					if(result.length() > 0 && getResult.length() > 0) {
						in = new Intent(ctx, ExceptionFeedbackListActivity.class);
						in.putExtra("initResultMsg", "获取成功");
						in.putExtra("initResult", result.toString());
						ctx.startActivity(in);
					} else {
						in = new Intent(ctx, ShipMentWelcomeActivity.class);
						in.putExtra("initResultMsg", "暂无数据");
						ctx.startActivity(in);
					}

				} catch (Exception e) {
					data.putString("msg", "系统异常，请重试...");
					e.printStackTrace();
				}
				msg.setData(data);
				break;
			// 提交异常反馈
			case HttpActConstant.SUBMIT_EXCEPTION_FEEDBACK_TASKS:
				try {
					System.out.println(params);
					result = HttpUtil
					        .queryStringForPost(HttpActConstant.SUBMIT_EXCEPTION_FEEDBACK_TASKS_URL, params, ctx);
					System.out.println(result);
					JSONObject jresult = new JSONObject(result.toString());
					if(jresult.getBoolean("result")) {
						data.putString(HttpConstant.SUBMIT_SUCCESS, HttpConstant.SUBMIT_SUCCESS);
						data.putString("msg", (jresult.has("msg") ? jresult.getString("msg")
						        : "提交成功！"));
					} else {
						data.putString(HttpConstant.SUBMIT_FAIL, HttpConstant.SUBMIT_FAIL);
						data.putString("msg", (jresult.has("msg") ? jresult.getString("msg")
						        : "提交失败，请重试..."));
					}
				} catch (Exception e) {
					data.putString("msg", "提交异常，请重试...");
					e.printStackTrace();
				}
				msg.setData(data);
				break;
			/**
			 * 图片上传
			 */
			case HttpActConstant.PICTURE_UPLOAD:
				try {
					String fileList = params.get("fpathList");
					String[] arr = fileList.split(",");
					if("[]".equals(arr[0].toString())) {

					} else {
						for(int index = 0;index < arr.length;index++) {
							String filePath = arr[index];
							if(arr.length == 1) {
								filePath = filePath.substring(1, filePath.length() - 1).trim();
							} else {
								if(index == 0) {
									filePath = filePath.substring(1).trim();

								}
								if(index == arr.length - 1) {
									filePath = filePath.substring(0, filePath.length() - 1).trim();
								}
							}
							// String filePath = params.get("fpath");
							filePath = filePath.trim();
							File file = new File(filePath);
							File sfile = new File(filePath + ".small50.jpg");
							FileOutputStream fos;
							fos = new FileOutputStream(sfile);
							Bitmap bitmap = PictureUtil.getSmallBitmap(filePath);
							bitmap.compress(Bitmap.CompressFormat.JPEG, 50, fos);
							fos.close();
							String mode = params.get("mode");
							System.out.println("file size:" + file.length() / 1024
							        + "K | sfile50 size:" + sfile.length() / 1024 + "K");
							if("GAO_QING".equals(mode)) {
								result = HttpUtil
								        .uploadPictureUtil(ctx, HttpActConstant.PICTURE_UPLOAD_URL, file);
							} else {
								result = HttpUtil
								        .uploadPictureUtil(ctx, HttpActConstant.PICTURE_UPLOAD_URL, sfile);
							}
							System.out.println(result);

							JSONObject jresult = new JSONObject(result.toString());
							JSONObject jdatas = jresult.has("entity") == false ? null : jresult
							        .getJSONObject("entity");
							boolean isPass = jresult.getBoolean("result");
							data.putString("fpath", filePath);
							if(isPass) {
								data.putString("picId", jdatas.getString("id"));
								DBUtil.updatePhotosStatusAndSubmitId(ctx, filePath, params
								        .get("taskId"), jdatas.getString("id"));
								data.putString("submit_result", HttpConstant.PHOTO_UPLOAD_SUCCESS);
								String message = jresult.has("msg") == false ? "" : jresult
								        .getString("msg");
								data.putString("msg", message);
							} else if("false".equals(isPass)) {
								String message = jresult.has("msg") == false ? "" : jresult
								        .getString("msg");
								data.putString("msg", message);
								data.putString("submit_result", HttpConstant.PHOTO_UPLOAD_FAIL);
							}
						}
						sp.setIsLastIndex(true);
					}

				} catch (Exception e) {
					e.printStackTrace();
					data.putString("submit_result", HttpConstant.PHOTO_UPLOAD_FAIL);
				}
				msg.setData(data);
				break;
			// 获取任务汇总
			case HttpActConstant.INIT_COLLECT_TASKS:
				try {
					System.out.println(params);
					result = HttpUtil
					        .queryStringForPost(HttpActConstant.INIT_COLLECT_TASKS_URL, params, ctx);
					System.out.println(result);
					JSONArray getResult = new JSONArray(result.toString());
					Intent in = null;
					if(result.length() > 0 && getResult.length() > 0) {
						in = new Intent(ctx, TasksCollectListActivity.class);
						in.putExtra("initResultMsg", "获取成功");
						in.putExtra("initResult", result.toString());
						ctx.startActivity(in);
					} else {
						in = new Intent(ctx, ShipMentWelcomeActivity.class);
						in.putExtra("initResultMsg", "暂无数据");
						ctx.startActivity(in);
					}

				} catch (Exception e) {
					data.putString("msg", "系统异常，请重试...");
					e.printStackTrace();
				}
				msg.setData(data);
				break;
			default:
				break;
		}
		String nmsg = data.getString("msg");
		if((result.indexOf("<html>") != -1 && result.indexOf("login") != -1)
		        || "没有登录或登录超时!".equals(data.getString("msg"))) {
			try {
				Map<String, String> params1 = new HashMap<String, String>();
				params1.put("account", sp.getAccount());
				params1.put("password", sp.getPassword());
				HttpUtil.queryStringForPost(HttpActConstant.LOGIN_URL, params1, ctx);
				nmsg = "请求超时，请重新提交操作。";
				data.putString("msg", nmsg);
			} catch (Exception e) {

			}
		}
		handler.sendMessage(msg);
	}
}
